package com.modules.timer.service.impl;

import com.common.base.BaseServiceImpl;
import com.modules.timer.util.TimerUtil;
import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.modules.timer.dao.TimerTaskDao;
import com.modules.timer.entity.TimerTaskEntity;
import com.modules.timer.service.TimerTaskService;

@Service
public class TimerTaskServiceImpl extends BaseServiceImpl<TimerTaskEntity> implements TimerTaskService {
	@Autowired
	private TimerTaskDao timerTaskDao;
    @Autowired
    private void setBaseMapper(){
        super.setBaseMapper(timerTaskDao);
    }

    @Autowired
    private Scheduler scheduler;

    //-----------------------------------------------------------------------------

    @Override
    public int insertTask(TimerTaskEntity t) {
        int result = timerTaskDao.insert(t);
        TimerUtil.createScheduleJob(scheduler, t);
        return result;
    }

    @Override
    public int updateTask(TimerTaskEntity t) {
        int result = timerTaskDao.updateByPrimaryKeySelective(t);
        if(result>0){
            TimerUtil.updateScheduleJob(scheduler, t);
        }
        return result;
    }


}
